package cn.leetcode;

public class Code108 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return fun(nums, 0, nums.length - 1);
    }


    public TreeNode fun(int[] nums, int left, int right) {
        if(left <= right){
            int i = left + right;
            int mid = i / 2;
            TreeNode treeNode = new TreeNode(nums[mid]);
            TreeNode treeNode1 = fun(nums, left, mid - 1);
            TreeNode treeNode2 = fun(nums, mid + 1, right);
            treeNode.left = treeNode1;
            treeNode.right = treeNode2;
            return treeNode;
        }
        return null;
    }
}
